package br.inf.ufrgs.usixml4desktop.rendering.javadesktop.components;

import java.awt.Dimension;
import java.text.NumberFormat;
import java.text.ParseException;

import javax.swing.JTextField;

import org.jdom.Element;

import br.inf.ufrgs.usixml4desktop.exceptions.ParsingErrorException;
import br.inf.ufrgs.usixml4desktop.rendering.UsiXMLElementRenderer;
import br.inf.ufrgs.usixml4desktopl.rendering.javadesktop.UsiXMLJavaDesktopInterfaceRenderer;
import br.inf.ufrgs.usixml4desktop.utils.PrimitiveElementParser;

public class UsiXMLJavaDesktopInputTextRenderer extends UsiXMLElementRenderer {

	public UsiXMLJavaDesktopInputTextRenderer(UsiXMLJavaDesktopInterfaceRenderer usiXMLInterfaceRenderer) {
		super(usiXMLInterfaceRenderer);
	}

	@Override
	public UsiXMLElementRenderer getNextRenderer() {
		return null;
	}

	@Override
	public String getValidElementName() {
		return "inputText";
	}

	@Override
	public Object processRenderization(Element element) throws ParsingErrorException {
		
		String name = element.getAttributeValue("name");
		String isVisible = element.getAttributeValue("isVisible");
		String isEnabled = element.getAttributeValue("isEnabled");
		String isEditable= element.getAttributeValue("isEditable");
//		String textColor = element.getAttributeValue("textColor");
//		int maxLength = NumberFormat.getIntegerInstance().parse(element.getAttributeValue("maxLength")).intValue();
		try {
			int numberOfColumns = NumberFormat.getIntegerInstance().parse(element.getAttributeValue("numberOfColumns")).intValue();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
  		
		PrimitiveElementParser parser = new PrimitiveElementParser();
		
		JTextField textField = new JTextField();
		textField.setName(name);
		textField.setVisible(parser.parseBoolean(isVisible));
		textField.setEnabled(parser.parseBoolean(isEnabled));
		textField.setEditable(parser.parseBoolean(isEditable));
		textField.setPreferredSize(new Dimension(175,25));
		
		return textField;
	}

	@Override
	public boolean validateElement(Element element) {
		return true;
	}

}
